package com.kxf.androidtestdemo.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.kxf.androidtestdemo.R;
import com.kxf.betterrefreshlayout.RefreshLayout;

public class TestRefreshLayoutActivity extends AppCompatActivity {
    private RefreshLayout rl;
    private ListView lv;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test_refresh_layout);

        initView();
    }

    private void initView() {
        rl = findViewById(R.id.rl);
        lv = findViewById(R.id.lv);

        int len = 30;
        String[] arrays = new String[len];
        for (int i=0;i<len;i++){
            arrays[i] = "listViewItem" + i;
        }

        lv.setAdapter(new ArrayAdapter<String>(this, R.layout.simple_list_item_1, R.id.text1, arrays));
//        View headerView = getLayoutInflater().inflate(R.layout.my_list_layout_header, null);
//        lv.addHeaderView(headerView);
        rl.setRefreshStateListener(new RefreshLayout.RefreshStateListender() {
            @Override
            public void onReadyRefresh(View headerView) {

            }

            @Override
            public void onCanRefresh(View headerView) {

            }

            @Override
            public void onRefresh(View headerView) {
                headerView.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        rl.refreshFinish(true);
                    }
                }, 10 * 1000);

            }

            @Override
            public void onFinish(View headerView, boolean isSuccess) {

            }
        });
    }
}